Monday, 22 April 2024

Fulltext Search in Mysql

1. What to use Fulltext Search for?

- Using for searching of text data in a large volumes, for text data stored in columns of type Char, Varchar, Text.

- Mode search in Fulltext search:

+ Natural language
+ Boolean search

- How Fulltext search working, ex:
We have 3 documents D1, D2, D3

D1 = "This is first document"
D2 = "This is second one"
D3 = "one two"

=> inverted index of 3 documents is:

"this" => {D1, D2}
"is" => {D1, D2}
"first" => {D1}
"document" => {D1}
"second" => {D2}
"one" => {D2, D3}
"two" => {D3}

=> search result of "this is first" is

{D1, D2} union {D1, D2} union {D1} = {D1}

- N-gram technique

 - Is technique device a string to children strings has same length (N) example: unigram (N=1), bigram (N=2), trigram (N=3). Ex apply when search Japanese language (because Japanese don't has space)

- Morphological Analysis: Using for searching natural language.

2. How to use Fulltext Search?

CREATE TABLE documents (
id INT AUTO_INCREMENT,
content TEXT,
PRIMARY KEY (id),
FULLTEXT (content)
);

-- Perform a Full-Text Search
SELECT * FROM documents WHERE MATCH(content) AGAINST('search query');

3. What does Fulltext Search include? 

Thank you

No comments:

Post a Comment

Golang Advanced Interview Q&A